<template>
	<view>
		<zero-loading type="circle" v-if="loading"></zero-loading>
		<view class="title "></view>

		<view class="cu-bar search ">
			<view class="search-form round">
				<text class="cuIcon-search text-white"></text>
				<input class="text-grey" @input="onKeyInput" @focus="InputFocus()" @blur="InputBlur()"
					:adjust-position="false" type="text" placeholder="栏位号/设备SN" confirm-type="search"
					v-model="inputValue"></input>
			</view>
			<view class="action">
				<view @tap="onScan()" class="flex justify-right text-xl">
					<text class="cuIcon-scan text-olive "></text>
				</view>
			</view>
		</view>

		<view class="padding-left padding-right flex">

			<view class="flex-treble align-center">
				<button @tap="onTabNodeType('')" :class="node_type==''?'':'line-grey'"
					class="cu-btn bg-blue shadow sm margin-right-xxs">全部</button>
				<button @tap="onTabNodeType('online')" :class="node_type=='online'?'':'line-grey'"
					class="cu-btn bg-olive shadow sm margin-right-xxs">在线</button>
			</view>
			<view class="flex-sub align-center justify-end text-right">
				<!-- <text class="text-olive ">全选</text> -->
				<button v-if="!selectAll" @tap="onSelectAll()"
					class="cu-btn bg-blue  shadow sm margin-right-xxs">全选</button>
				<button v-if="selectAll" @tap="onUnSelectAll()"
					class="cu-btn bg-blue  shadow sm margin-right-xxs">全不选</button>
			</view>


		</view>
		<scroll-view scroll-y="true" class="scroll-Y padding-bottom-sm padding-top-sm"
			:style='{ height: nodeScrollHeight }'>
			<block v-for="(item, idx) in nodeList" :key="idx">
				<view class="node-pannel margin-sm " :class="item.select?'border-select':''" hover-class="opcity"
					hover-stay-time="150" @tap="onTapFeedNode(item)">
					<view class="padding-sm flex align-center">

						<block v-if="op_type!='hnum'">
							<view class="flex-sub  text-left">
								<text :class="item.online>0?'text-green':'text-gray'" class="iconfont icon-siweiqi"></text>
								<text :class="item.online<1?'text-gray':'text-green'" class=" padding-left-xs">{{item.hnum}}</text>
							</view>

							<view class="flex-sub  text-center">
								<view v-if="item.model && item.model=='fg'" class="margin-left-xs cu-tag radius sm line-gray">粥料</view>
								<text v-if="item.mode>0" class="text-white  padding-left-xs">{{item.mode_day}}</text>
								<text v-if="item.mode==0" class="text-orange  padding-left-xs">停用</text>
							</view>

							<view class="flex-sub text-right flex justify-end align-center">
								<block v-if="item.select>0">
									<view v-if="item.run_status==0" class=''>

									</view>
									<view v-if="item.run_status==1" class=''>
										<text class="cuIcon-loading2 cuIconfont-spin text-white"></text>
									</view>
									<view v-if="item.run_status==-1" class=''>
										<text class="padding-left-xs text-orange">失败</text>
									</view>
									<view v-if="item.run_status==2" class=' '>
										<text class="padding-left-xs text-olive">成功</text>
									</view>
								</block>
							</view>
						</block>

						<block v-if="op_type=='hnum'">
							<view class="flex-twice  text-left">
								<text :class="item.online<1?'text-gray':'text-olive'" class=" padding-left-xs text-xs">序号:{{item.tn+1}} 编码:{{item.sn}}</text>
							</view>
							<view class="flex-sub  text-center">
								<!-- <text class="text-orange  padding-left-xs">{{item.hnum}}</text> -->
								<button @tap.stop="onTapHnum(item,idx)" class="cu-btn line-orange"> {{item.hnum}} <text class="cuIcon-edit padding-left-xs"></text></button>
							</view>
							<view class="flex-sub text-right flex justify-end align-center">
								<block v-if="item.select>0">
									<view v-if="item.run_status==0" class=''>

									</view>
									<view v-if="item.run_status==1" class=''>
										<text class="cuIcon-loading2 cuIconfont-spin text-white"></text>
									</view>
									<view v-if="item.run_status==-1" class=''>
										<text class="padding-left-xs text-orange">失败</text>
									</view>
									<view v-if="item.run_status==2" class=' '>
										<text class="padding-left-xs text-olive">成功</text>
									</view>
								</block>
							</view>
						</block>
						
					</view>
				</view>
			</block>
		</scroll-view>
		<view class="padding-left-lg padding-right-lg">
			<block v-if="apply_run>0">
				<button @tap="onStop" class="cu-btn block bg-orange margin-tb-sm lg">
					<text class="cuIcon-stop"></text>
					<text class="text-sm padding-left-xs">终止 </text>
					<text class="text-sm padding-left">(当前下发第{{apply_idx+1}}个栏位中)</text>
				</button>
			</block>
			<block v-if="apply_run==0">
				<button @tap="onMenu" :class="selectNum>0?'bg-blue':'bg-grey'" class="cu-btn block  margin-tb-sm lg">
					<text class="iconfont icon-shouye1"></text>
					<text class="text-sm padding-left-xs">下发 </text>
					<text class="text-sm padding-left">(当前选中{{selectNum}}个栏位)</text>
				</button>
			</block>

		</view>


		<view class="cu-modal bottom-modal" :class="showMenu?'show':''" @tap="hideModal">
			<view class="cu-dialog">
				<!-- <view class="cu-bar bg-white">
											<view class="action text-green" @tap="hideModal">确定</view>
											<view class="action text-gray" @tap="hideModal">取消</view>
										</view> -->
				<view class="">
					<view class="cu-list menu">
						<view class="cu-item arrow" @tap="onMenu('feed')">
							<view class="content">
								<text class="iconfont icon-feed1 text-grey"></text>
								<text class="text-grey padding-left-xs">下料/下水</text>
							</view>
						</view>

						<view class="cu-item arrow" @tap="onMenu('offset')">
							<view class="content">
								<text class="cuIcon-order text-grey"></text>
								<text class="text-grey">调整料量</text>
							</view>
						</view>

						<view class="cu-item arrow" @tap="onMenu('calc')">
							<view class="content">
								<text class="cuIcon-focus text-grey"></text>
								<text class="text-grey">下料校准</text>
							</view>
						</view>



						<!-- <view v-if="mode==1" class="cu-item arrow" @tap="onMenu('born')">
							<view class="content">
								<text class="cuIcon-female text-grey"></text>
								<text class="text-grey">一键分娩</text>
							</view>
						</view> -->
						<view class="cu-item arrow" @tap="onMenu('day')">
							<view class="content">
								<text class="cuIcon-time text-grey"></text>
								<text class="text-grey">设置日龄</text>
							</view>
						</view>
						<view class="cu-item arrow" @tap="onMenu('plan')">
							<view class="content">
								<text class="cuIcon-tag text-grey"></text>
								<text class="text-grey">应用方案</text>
							</view>
						</view>
						<view class="cu-item arrow" @tap="onMenu('stop')">
							<view class="content">
								<text class="cuIcon-stop text-grey"></text>
								<text class="text-grey">停止饲喂</text>
							</view>
						</view>
					</view>


				</view>
			</view>
		</view>

		<view class="cu-modal bottom-modal" :class="showMenuHnum?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">

					<view class="action text-gray" @tap="hideModalHnum">取消</view>
					<view class="action text-green" @tap="onSetHnum">确定</view>
				</view>

				<view class="padding flex justify-begin">
					<text class="iconfont icon-tishi1 text-green"></text>
					<text class="text-md text-grey text-sm">请选取字母排号和数字列号组合，如A排+7列=A07</text>
				</view>

				<view class="padding flex align-center justify-center">
					<text class="text-green text-xxl">{{ set_hnum_prefix }}{{ set_hnum }}</text>
				</view>

				<view class="padding flex align-center">
					<view class=" flex-sub text-left text-grey">排号</view>
					<view class="flex-treble align-center">
						<button @tap="onTabHnumPrefix('A')" :class="set_hnum_prefix=='A'?'':'line-grey'"
							class="cu-btn bg-green shadow sm margin-right-xs">A</button>
						<button @tap="onTabHnumPrefix('B')" :class="set_hnum_prefix=='B'?'':'line-grey'"
							class="cu-btn bg-green shadow sm margin-right-xs">B</button>
						<button @tap="onTabHnumPrefix('C')" :class="set_hnum_prefix=='C'?'':'line-grey'"
							class="cu-btn bg-green  shadow sm margin-right-xs">C</button>
						<button @tap="onTabHnumPrefix('D')" :class="set_hnum_prefix=='D'?'':'line-grey'"
							class="cu-btn bg-green  shadow sm margin-right-xs">D</button>
						<button @tap="onTabHnumPrefix('E')" :class="set_hnum_prefix=='E'?'':'line-grey'"
							class="cu-btn bg-green  shadow sm margin-right-xs">E</button>
						<button @tap="onTabHnumPrefix('F')" :class="set_hnum_prefix=='F'?'':'line-grey'"
							class="cu-btn bg-green  shadow sm margin-right-xs">F</button>
						<button @tap="onTabHnumPrefix('G')" :class="set_hnum_prefix=='G'?'':'line-grey'"
							class="cu-btn bg-green  shadow sm margin-right-xs">G</button>
					</view>
				</view>

				<view class="padding flex align-center">
					<view class=" flex-sub text-left text-grey">列号</view>
					<view class=" flex-treble text-right justify-center">
						<slider :value="set_hnum" block-size="35" step="1" @change="hnumSliderChange" min="1"
							max="99" activeColor="#39b54a" block-color="#39b54a" show-value />
					</view>
				</view>

				<view class="padding flex align-center">
					
				</view>

				<view class="padding flex align-center">
					
				</view>
			</view>
		</view>

		<view class="cu-modal bottom-modal" :class="showMenuFeed?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">

					<view class="action text-gray" @tap="hideModalFeed">取消</view>
					<view class="action text-green" @tap="confirmSetFeed">确定</view>
				</view>

				<view class="padding flex justify-begin">
					<text class="iconfont icon-tishi1 text-green"></text>
					<text class="text-md text-grey text-sm">数值0表示不进行下料/下水</text>
				</view>

				<view class="padding flex align-center">
					<view class=" flex-sub text-left text-grey">下料(g):</view>
					<view class=" flex-treble text-right justify-center">
						<slider :value="set_feed" block-size="25" step="50" @change=" feedSliderChange " min="0"
							max="1000" activeColor="#39b54a" block-color="#39b54a" show-value />
					</view>
				</view>

				<view class="padding flex align-center">
					<view class=" flex-sub text-left text-grey">下水(ml):</view>
					<view class=" flex-treble text-right justify-center">
						<slider :value="set_water" block-size="25" step="50" @change="waterSliderChange" min="0"
							max="1000" activeColor="#39b54a" block-color="#39b54a" show-value />
					</view>
				</view>
			</view>
		</view>

		<view class="cu-modal bottom-modal" :class="showMenuOffset?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">

					<view class="action text-gray" @tap="hideModalOffset">取消</view>
					<view class="action text-green" @tap="confirmSetOffset">确定</view>
				</view>

				<view class="padding flex justify-begin">
					<text class="iconfont icon-tishi1 text-green"></text>
					<text class="text-md text-grey text-sm">设置增加减少饲喂量 </text>
				</view>

				<view class="padding flex align-center">
					<view class=" flex-sub text-left text-grey">增加/减少(g):</view>
					<view class=" flex-treble text-right justify-center">
						<slider :value="set_offset" block-size="20" step="100" @change=" offsetSliderChange "
							min="-1000" max="1000" activeColor="#39b54a" block-color="#39b54a" show-value />
					</view>
				</view>
			</view>
		</view>

		<view class="cu-modal bottom-modal" :class="showMenuCalc?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">

					<view class="action text-gray" @tap="hideModalCalc">取消</view>
					<view class="action text-green" @tap="confirmSetCalc">确定</view>
				</view>

				<view class="padding flex justify-begin">
					<!-- <text class="iconfont icon-tishi1 text-green"></text> -->
					<text class="text-md text-grey text-sm">请输入10圈出料(g)</text>
				</view>

				<view class="padding">

					<view class="uni-input-wrapper">
						<input v-model="set_calc" class="uni-input"
							style="height: 45px;line-height: 35px;border: 1px solid #aaa;font-size: 20px;border-radius: 10px;"
							maxlength="5" type="number" placeholder="" />
					</view>
				</view>

				<view class="padding flex justify-begin">

				</view>

			</view>
		</view>

		<view class="cu-modal bottom-modal" :class="showMenuDay?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">

					<view class="action text-gray" @tap="hideModalDay">取消</view>
					<view class="action text-green" @tap="confirmSetDay">确定</view>
				</view>

				<view class="padding flex justify-begin">
					<!-- <text class="iconfont icon-tishi1 text-green"></text> -->
					<text class="text-md text-grey text-sm">请输入日龄</text>
				</view>

				<view class="padding">

					<view class="uni-input-wrapper">
						<input v-model="set_day" class="uni-input"
							style="height: 45px;line-height: 35px;border: 1px solid #aaa;font-size: 20px;border-radius: 10px;"
							maxlength="4" type="number" placeholder="" />
					</view>
				</view>

				<view class="padding flex justify-begin">

				</view>

			</view>
		</view>

		<view class="cu-modal bottom-modal" :class="showMenuPlan?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">

					<view class="action text-gray" @tap="hideModalPlan">取消</view>
					<view class="action text-green" @tap="confirmSetPlan">确定</view>
				</view>

				<view class="padding flex justify-begin">
					<text class="iconfont icon-tishi1 text-green"></text>
					<text class="text-md text-grey text-sm">请选择方案后点击[确定]</text>
				</view>

				<view class="padding">
					<scroll-view scroll-y="true" class="scroll-Y " style="height: 500rpx;">
						<block v-for="(item, idx) in planList" :key="idx">
							<view @tap="onPlanSelect(idx)" :class="item.select>0?'bg-select':'bg-unselect'"
								class="device-pannel margin-sm " hover-class="opcity" hover-stay-time="150">
								<view class="padding-sm flex align-center">
									<view class="flex-treble text-left">
										<text v-if="item.global>0"
											class="iconfont icon-moban-xitongmoban text-orange"></text>
										<text class=" text-grey padding-left-xs">{{item.name}}</text>

									</view>
									<view class="flex-sub text-right justify-center">
										<text class="text-grey">{{item.food_plan}}</text>
									</view>
								</view>
							</view>
						</block>
					</scroll-view>
				</view>

				<view class="padding">

				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import * as api from 'common/api.js';
	const moment = require("../../common/moment.min.js");
	import * as echarts from '@/uni_modules/lime-echart/static/echarts.min'
	import * as util from '../../common/util.js'
	import {
		API_HEAD
	} from '../../common/api.js'
	const retry_max = 2
	export default {
		data() {
			return {
				scrollHeight: 0,
				innerScrollHeight: 0,
				nodeScrollHeight: 0,
				TabCur: 0,
				loading: false,

				op_type: '',
				housename: '',
				houseid: '',

				node_type: '',
				inputValue: '',

				selectAll: false,

				nodeList: [],
				selectNodeList: [],

				showMenu: false,
				showMenuHnum: false,
				showMenuFeed: false,
				showMenuDay: false,
				showMenuCalc: false,
				showMenuOffset: false,
				showMenuPlan: false,

				mode: '',
				cur_edit_hnum_idx:-1,//当前编辑栏位号的序号
				set_hnum: 1,
				set_hnum_prefix: 'A',
				set_feed: 100,
				set_water: 0,
				set_day: 1,
				set_offset: 0,
				set_calc: 1000,

				planList: [],
				selectNum: 0,

				select_plan_idx: 0,
				apply_idx: 0,
				apply_run: 0,
				apply_retry: 0,
			}
		},
		onReady() {
			// 计算scroll-view高度
			uni.getSystemInfo({
				success: resu => {
					//console.info("窗口高度:", resu.windowHeight)
					const query = uni.createSelectorQuery()
					query.select('.title').boundingClientRect()
					query.exec(res => {
						console.info("resu.windowHeight:", resu.windowHeight)
						console.info("顶部下拉区域:", res[0].height)
						this.nodeScrollHeight = resu.windowHeight - res[0].height - 10 - 50 - 24 -
							50 + 'px';
					})
				}
			})
		},
		onLoad(option) {
			console.info("load batch_op", option)
			if (option.housename) {
				this.housename = option.housename
			}
			if (option.houseid) {
				this.houseid = option.houseid
			}
			if (option.op_type) {
				this.op_type = option.op_type
			}
			if (this.op_type == '') {
				// uni.navigateBack({
				// 	delta: 1
				// });
			}
		},
		onShow: function() {
			console.info("show batch_op")
			// 保持屏幕常亮
			// #ifdef APP-PLUS
			uni.setKeepScreenOn({
				keepScreenOn: true
			});
			// #endif
			uni.setNavigationBarTitle({
				title: this.housename
			});
			this.loadRooms(true)
		},
		onUnload:function(){
			console.info("unload batch_op")
			// 保持屏幕常亮
			// #ifdef APP-PLUS
			uni.setKeepScreenOn({
				keepScreenOn: false
			});
			// #endif
		},
		methods: {
			onSelectAll() {
				this.selectAll = true
				for (var i = 0; i < this.nodeList.length; i++) {
					this.nodeList[i].select = 1
				}
				this.selectNum = this.nodeList.length
			},
			onUnSelectAll() {
				this.selectAll = false
				for (var i = 0; i < this.nodeList.length; i++) {
					this.nodeList[i].select = 0
				}
				this.selectNum = 0
			},
			onTabNodeType(val) {
				this.node_type = val
				console.info("onTabNodeType", this.node_type)
				this.loadRooms(true)
			},
			onKeyInput(event) {
				this.inputValue = event.target.value
				console.info("inputValue", this.inputValue)
				this.loadRooms(true)
			},
			InputFocus() {

			},
			InputBlur() {

			},
			onTapFeedNode(item) {
				//console.info(JSON.stringify(item))
				for (var i = 0; i < this.nodeList.length; i++) {
					if (this.nodeList[i].sn == item.sn) {
						this.nodeList[i].select = (this.nodeList[i].select ? 0 : 1)
						break
					}
				}
				var selectNum = 0
				for (var i = 0; i < this.nodeList.length; i++) {
					if (this.nodeList[i].select == 1) {
						selectNum++
					}
				}
				this.selectNum = selectNum
			},
			showModal() {
				this.showMenu = true
			},
			showModelHnum() {
				this.showMenuHnum = true
			},
			showModelFeed() {
				this.showMenuFeed = true
				this.set_feed = 100
				this.set_water = 0
			},
			showModelOffset() {
				this.showMenuOffset = true
				this.set_offset = 0
			},
			showModelDay() {
				this.showMenuDay = true
				this.set_day = 1
			},
			showModelCalc() {
				this.showMenuCalc = true
				this.set_calc = 1000
			},
			showModelPlan() {
				this.showMenuPlan = true
				this.loadPlan()
			},
			hideModal() {
				console.info("hideModal")
				this.showMenu = false
			},
			hideModalHnum() {
				this.showMenuHnum = false
			},
			hideModalFeed() {
				this.showMenuFeed = false
			},
			hideModalOffset() {
				this.showMenuOffset = false
			},
			hideModalDay() {
				this.showMenuDay = false
			},
			hideModalCalc() {
				this.showMenuCalc = false
			},
			hideModalPlan() {
				this.showMenuPlan = false
			},
			hnumSliderChange(e) {
				console.log('hnum value 发生变化：' + e.detail.value)
				let num = e.detail.value
				if(num<10){
					this.set_hnum = "0"+num.toString()
				}else{
					this.set_hnum = num.toString()
				}
				//this.set_hnum = e.detail.value.padStart(3, '0')
			},
			waterSliderChange(e) {
				console.log('water value 发生变化：' + e.detail.value)
				this.set_water = e.detail.value
			},
			feedSliderChange(e) {
				console.log('feed value 发生变化：' + e.detail.value)
				this.set_feed = e.detail.value
			},
			offsetSliderChange(e) {
				console.log('offset value 发生变化：' + e.detail.value)
				this.set_offset = e.detail.value
			},
			onMenu() {
				if (this.selectNum == 0) {
					uni.showToast({
						title: '请先选择栏位',
						icon: 'error'
					})
					return
				}
				
				
				console.info("onMenu", this.op_type)
				if (this.op_type == 'hnum') {
					this.confirmSetHnum()
				}
				else if (this.op_type == 'feed') {
					this.showModelFeed()
				} else if (this.op_type == 'offset') {
					this.showModelOffset()
				} else if (this.op_type == 'day') {
					this.showModelDay()
				} else if (this.op_type == 'calc') {
					this.showModelCalc()
				} else if (this.op_type == 'stop') {
					this.confirmSetStop()
				} else if (this.op_type == 'plan') {
					this.showModelPlan()
				} else {
					uni.showToast({
						title: '您没有权限',
						icon: 'error'
					})
				}
			},
			onTapHnum(item,idx){
				this.cur_edit_hnum_idx = idx
				
				var hnum = item.hnum
				this.set_hnum = hnum.substring(1)
				this.set_hnum_prefix = hnum.substring(0,1)

				this.showModelHnum()
			},
			onTabHnumPrefix(str){
				this.set_hnum_prefix = str
			},
			onStop() {
				this.apply_idx = 0
				this.apply_run = 0
				for (var i = 0; i < this.nodeList.length; i++) {
					this.nodeList[i].run_status = 0
				}
				this.$forceUpdate()
				uni.showModal({
					title: '停止',
					content: "您已经终止操作",
					showCancel: false
				})
			},
			onPlanSelect(idx) {
				console.info("onPlanSelect", idx)
				for (var i = 0; i < this.planList.length; i++) {
					this.planList[i].select = 0
				}
				this.planList[idx].select = 1
				this.$forceUpdate()
			},

			loadRooms(show_load) {
				var that = this
				var token = getApp().getToken()
				if (that.houseid == '') {
					return
				}

				var online = ''
				var alarm = ''
				if (that.node_type == "") {
					online = ''
					alarm = ''
				} else if (that.node_type == "online") {
					online = '1'
					alarm = ''
				} else if (that.node_type == "offline") {
					online = '0'
					alarm = ''
				} else if (that.node_type == "alarm") {
					online = ''
					alarm = '1'
				}

				if (show_load) {
					that.loading = true
				}
				api.myRequest({
					url: '/Api/Device/Feednode',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': 'Bearer ' + token + ''
					},
					data: {
						houseid: that.houseid,
						device_type: 'DMXFGW',
						online: online,
						alarm: alarm,
						key: that.inputValue
					},
				}, false).then(res => {
					that.loading = false
					if (res.code >= 0) {
						//console.info(res)
						var list = res.data
						for (var i = 0; i < list.length; i++) {
							var mode_str
							if(!list[i].model || list[i].model=="feed"){
								mode_str = util.decodeModeNew(list[i].mode)
								if (list[i].mode == 0 || list[i].mode == 5) {
									list[i].mode_day = mode_str
								} else {
									list[i].mode_day = mode_str + ' ' + list[i].day + '天'
								}
							}else if(list[i].model && list[i].model=="fg"){
								mode_str = util.decodeFg(list[i].mode)
								if (list[i].mode == 0 || list[i].mode == 3) {
									list[i].mode_day = mode_str
								} else {
									list[i].mode_day = mode_str + ' ' + list[i].day + '天'
								}
							}

							list[i].day_use_water_auto = list[i].day_use_water_auto ? list[i].day_use_water_auto :
								0
							list[i].day_use_water_man = list[i].day_use_water_man ? list[i].day_use_water_man : 0
							list[i].day_use_feed_auto = list[i].day_use_feed_auto ? list[i].day_use_feed_auto : 0
							list[i].day_use_feed_man = list[i].day_use_feed_man ? list[i].day_use_feed_man : 0
							list[i].max_feed = list[i].max_feed ? list[i].max_feed : 0

							list[i].pig_num = list[i].pig_num ? list[i].pig_num : 0
							list[i].son = list[i].son ? list[i].son : 0

							var water = parseFloat(list[i].day_use_water_auto) + parseFloat(list[i]
								.day_use_water_man)
							list[i].water = parseFloat(water.toFixed(2).toString()).toString();

							var feed = parseFloat(list[i].day_use_feed_auto) + parseFloat(list[i].day_use_feed_man)
							var per = 0
							if (list[i].max_feed > 0) {
								per = parseFloat((feed / parseFloat(list[i].max_feed) * 100).toFixed(1))
							} else {
								per = 0
							}

							list[i].feed = parseFloat(feed.toFixed(2))
							list[i].per = per
							list[i].max_feed = parseFloat(list[i].max_feed)

							

							//根据tn推断栏位号
							/*var new_hnum =""
							let num = list[i].tn+1
							if(num<10){
								new_hnum = "00"+num.toString()
							}else if(num<100){
								new_hnum = "0"+num.toString()
							}else{
								new_hnum = num.toString()
							}
							new_hnum = "A"+new_hnum
							list[i].hnum = new_hnum
							*/

							list[i].select = 0 //默认未选择
							list[i].run_status = 0
						}
						that.nodeList = list

					} else {

					}
				}).catch(err => {
					that.loading = false
					console.log(err)
				})
			},

			confirmSetFeed() {
				var that = this
				this.selectNodeList = []
				for(var i=0;i<this.nodeList.length;i++){
					if(this.nodeList[i].select>0){
						this.selectNodeList.push(this.nodeList[i])
					}
				}
				console.info("已选择:"+this.selectNodeList.length)
				
				that.hideModalFeed()
				uni.showModal({
					title: '提示',
					content: '请注意,您即将对' + that.selectNum + '个栏位设置 远程下料:' + that.set_feed + 'g,远程下水:' + that
						.set_water + ' ml,您的操作将会被系统记录',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							for (var i = 0; i < that.nodeList.length; i++) {
								that.nodeList[i].run_status = 0
							}

							that.apply_idx = 0
							that.apply_run = 1
							that.apply_retry = 0
							that.loopSetNodeFeed()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			loopSetNodeFeed() {
				var that = this
				if (!that.apply_run) {
					return;
				}
				var node = that.selectNodeList[that.apply_idx]
				var real_idx = that.getIdxBySn(node.sn)
				that.nodeList[real_idx].run_status = 1
				that.setNodeFeed(node.addr, node.tn, that.set_feed,that.set_water).then(function(res) {
					if (res.code >= 0) {
						that.nodeList[real_idx].run_status = 2
						//判断是否结束
						if (that.apply_idx == (that.selectNodeList.length - 1)) {
							//结束
							uni.showModal({
								title: '提示',
								content: "设置已经完成",
								showCancel: false
							})
							that.apply_run = 0
						} else {
							//下一个
							that.apply_idx++
							that.apply_retry = 0
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeFeed()
								}, 200)
							}


						}
					} else {
						//遇到错误，重试
						if (that.apply_retry < retry_max) {
							that.nodeList[real_idx].run_status = 1
							that.apply_retry++
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeFeed()
								}, 200)
							}
						} else {
							//超过重试次数，失败
							that.nodeList[real_idx].run_status = -1
							//判断是否结束
							if (that.apply_idx == (that.selectNodeList.length - 1)) {
								//结束
								uni.showModal({
									title: '提示',
									content: "设置已经完成",
									showCancel: false
								})
								that.apply_run = 0
							} else {
								//下一个
								that.apply_idx++
								that.apply_retry = 0
								if (that.apply_run) {
									setTimeout(function() {
										that.loopSetNodeFeed()
									}, 200)
								}
							}
						}
					}
				})
			},
			setNodeFeed(addr, tn, set_feed, set_water) {
				var promise = new Promise(function(resolve, reject) {
					var token = getApp().getToken()
					api.myRequest({
						url: '/Api/Device/Gw/ManualFeed',
						method: 'PUT',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authorization': 'Bearer ' + token + ''
						},
						data: {
							addr: addr,
							tn: tn,
							feed: set_feed,
							water: set_water
						},
					}, false).then(res => {
						resolve(res);
					}).catch(err => {
						console.log(err)
						reject(err);
					})
				});
				return promise;
			},
			
			
			confirmSetOffset() {
				var that = this
				this.selectNodeList = []
				for(var i=0;i<this.nodeList.length;i++){
					if(this.nodeList[i].select>0){
						this.selectNodeList.push(this.nodeList[i])
					}
				}
				console.info("已选择:"+this.selectNodeList.length)
				
				that.hideModalOffset()
				uni.showModal({
					title: '提示',
					content: '请注意,您即将对' + that.selectNum + '个栏位设置增加/减少料量:' + that.set_offset + 'g,您的操作将会被系统记录',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							for (var i = 0; i < that.nodeList.length; i++) {
								that.nodeList[i].run_status = 0
							}
			
							that.apply_idx = 0
							that.apply_run = 1
							that.apply_retry = 0
							that.loopSetNodeOffset()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			loopSetNodeOffset() {
				var that = this
				if (!that.apply_run) {
					return;
				}
				var node = that.selectNodeList[that.apply_idx]
				var real_idx = that.getIdxBySn(node.sn)
				that.nodeList[real_idx].run_status = 1
				that.setNodeOffset(node.addr, node.tn, that.set_offset).then(function(res) {
					if (res.code >= 0) {
						that.nodeList[real_idx].run_status = 2
						//判断是否结束
						if (that.apply_idx == (that.selectNodeList.length - 1)) {
							//结束
							uni.showModal({
								title: '提示',
								content: "设置已经完成",
								showCancel: false
							})
							that.apply_run = 0
						} else {
							//下一个
							that.apply_idx++
							that.apply_retry = 0
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeOffset()
								}, 200)
							}
			
			
						}
					} else {
						//遇到错误，重试
						if (that.apply_retry < retry_max) {
							that.nodeList[real_idx].run_status = 1
							that.apply_retry++
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeOffset()
								}, 200)
							}
						} else {
							//超过重试次数，失败
							that.nodeList[real_idx].run_status = -1
							//判断是否结束
							if (that.apply_idx == (that.selectNodeList.length - 1)) {
								//结束
								uni.showModal({
									title: '提示',
									content: "设置已经完成",
									showCancel: false
								})
								that.apply_run = 0
							} else {
								//下一个
								that.apply_idx++
								that.apply_retry = 0
								if (that.apply_run) {
									setTimeout(function() {
										that.loopSetNodeOffset()
									}, 200)
								}
							}
						}
					}
				})
			},
			setNodeOffset(addr, tn, set_offset) {
				var promise = new Promise(function(resolve, reject) {
					var token = getApp().getToken()
					api.myRequest({
						url: '/Api/Device/Gw/SetNodeFeedOffset',
						method: 'PUT',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authorization': 'Bearer ' + token + ''
						},
						data: {
							addr: addr,
							tn: tn,
							feedOffset: set_offset/100
						},
					}, false).then(res => {
						resolve(res);
					}).catch(err => {
						console.log(err)
						reject(err);
					})
				});
				return promise;
			},

			loadPlan() {
				var that = this
				var token = getApp().getToken()
				that.loading = true
				api.myRequest({
					url: '/Api/FeedPlanNew',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': 'Bearer ' + token + ''
					},
					data: {

					},
				}, false).then(res => {
					that.loading = false
					if (res.code >= 0) {
						that.planList = res.data
					} else {

					}
				}).catch(err => {
					that.loading = false
					console.log(err)
				})
			},

			confirmSetPlan() {
				var that = this

				this.selectNodeList = []
				for(var i=0;i<this.nodeList.length;i++){
					if(this.nodeList[i].select>0){
						this.selectNodeList.push(this.nodeList[i])
					}
				}
				console.info("已选择:"+this.selectNodeList.length)
				
				that.select_plan_idx = -1
				for (var i = 0; i < that.planList.length; i++) {
					if (that.planList[i].select == 1) {
						that.select_plan_idx = i
						break
					}
				}

				if (that.select_plan_idx < 0) {
					//that.hideModalPlan()
					console.info("that.select_plan_idx:未选择", that.select_plan_idx)
					uni.showToast({
						title: '请先选择方案',
						icon: 'error'
					})
					// uni.showModal({
					// 	title: '提示',
					// 	content: '请选选择方案',
					// 	showCancel: false
					// })
				} else {

					var plan = that.planList[that.select_plan_idx]
					/*
					console.info("plan para:", plan.para)
					console.info("old para:", that.para)
					//备份不被覆盖的参数
					var plan_para = JSON.parse(plan.para)
					var old_para = JSON.parse(that.para)
					var Sn = old_para.Sn
					var Passwd = old_para.Passwd
					var Gday = old_para.Gday
					var Hnum = old_para.Hnum

					var new_para = JSON.parse(JSON.stringify(plan_para))
					new_para.Sn = Sn
					new_para.Passwd = Passwd
					new_para.Gday = Gday
					new_para.Hnum = Hnum
					*/

					//that.setParam(plan, new_para)
					that.hideModalPlan()
					uni.showModal({
						title: '提示',
						content: '请注意,您即将对' + that.selectNum + '个栏位设置方案:[' + plan.name + '] ,您的操作将会被系统记录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								for (var i = 0; i < that.nodeList.length; i++) {
									that.nodeList[i].run_status = 0
								}

								that.apply_idx = 0
								that.apply_run = 1
								that.apply_retry = 0
								that.loopSetNodeParam()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}

			},
			loopSetNodeParam() {
				var that = this
				if (!that.apply_run) {

					return;
				}

				var plan = that.planList[that.select_plan_idx]
				console.info("plan.name",plan.name)
				console.info("plan.id",plan.id)
				if(!plan.id || isNaN(plan.id)){
					uni.showModal({
						title: '错误',
						content: "方案选择异常,下发退出",
						showCancel: false
					})
					return
				}

				var node = that.selectNodeList[that.apply_idx]
				var real_idx = that.getIdxBySn(node.sn)

				//备份不被覆盖的参数
				var plan_para = JSON.parse(plan.para)
				var old_para = JSON.parse(node.para)
				var Sn = old_para.Sn
				var Passwd = old_para.Passwd
				var Gday = old_para.Gday
				var Hnum = old_para.Hnum

				var new_para = JSON.parse(JSON.stringify(plan_para))
				new_para.Sn = Sn
				new_para.Passwd = Passwd
				new_para.Gday = Gday
				new_para.Hnum = Hnum

				that.nodeList[real_idx].run_status = 1
				that.setNodePara(plan.id, node.addr, node.tn, new_para,node.sn).then(function(res) {
					if (res.code >= 0) {
						that.nodeList[real_idx].run_status = 2
						//判断是否结束
						if (that.apply_idx == (that.selectNodeList.length - 1)) {
							//结束
							uni.showModal({
								title: '提示',
								content: "设置已经完成",
								showCancel: false
							})
							that.apply_run = 0
						} else {
							//下一个
							that.apply_idx++
							that.apply_retry = 0
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeParam()
								}, 200)
							}


						}
					} else {
						//遇到错误，重试
						if (that.apply_retry < retry_max) {
							that.nodeList[real_idx].run_status = 1
							that.apply_retry++
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeParam()
								}, 200)
							}
						} else {
							//超过重试次数，失败
							that.nodeList[real_idx].run_status = -1
							//判断是否结束
							if (that.apply_idx == (that.selectNodeList.length - 1)) {
								//结束
								uni.showModal({
									title: '提示',
									content: "设置已经完成",
									showCancel: false
								})
								that.apply_run = 0
							} else {
								//下一个
								that.apply_idx++
								that.apply_retry = 0
								if (that.apply_run) {
									setTimeout(function() {
										that.loopSetNodeParam()
									}, 200)
								}
							}
						}
					}
				})

			},
			setNodePara(feed_plan_id, addr, tn, nodePara,sn) {
				var model = ''
				if(sn[0]=='3'){
					model = 'fg'
				}else{
					model = 'feed'
				}
				var url = ''
				if(model=="feed"){
					url = '/Api/Device/Gw/NodeParam';
				}else if(model=="fg"){
					url = '/Api/Device/Gw/NodeFgParam';
				}
				var promise = new Promise(function(resolve, reject) {
					var token = getApp().getToken()
					api.myRequest({
						url: url,
						method: 'PUT',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authorization': 'Bearer ' + token + ''
						},
						data: {
							addr: addr,
							tn: tn,
							params: JSON.stringify(nodePara),
							enable: '1',
							feed_plan_id: feed_plan_id
						},
					}, false).then(res => {
						resolve(res);
					}).catch(err => {
						console.log(err)
						reject(err);
					})
				});
				return promise;
			},

			confirmSetDay() {
				var that = this
				this.selectNodeList = []
				for(var i=0;i<this.nodeList.length;i++){
					if(this.nodeList[i].select>0){
						this.selectNodeList.push(this.nodeList[i])
					}
				}
				console.info("已选择:"+this.selectNodeList.length)
				
				that.hideModalDay()
				uni.showModal({
					title: '提示',
					content: '请注意,您即将对' + that.selectNum + '个栏位设置日龄:' + that.set_day + ' ,您的操作将会被系统记录',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							for (var i = 0; i < that.nodeList.length; i++) {
								that.nodeList[i].run_status = 0
							}

							that.apply_idx = 0
							that.apply_run = 1
							that.apply_retry = 0
							that.loopSetNodeDay()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			loopSetNodeDay() {
				var that = this
				if (!that.apply_run) {
					return;
				}
				var node = that.selectNodeList[that.apply_idx]
				var real_idx = that.getIdxBySn(node.sn)
				that.nodeList[real_idx].run_status = 1
				that.setNodeDay(node.addr, node.tn, that.set_day).then(function(res) {
					if (res.code >= 0) {
						that.nodeList[real_idx].run_status = 2
						//判断是否结束
						if (that.apply_idx == (that.selectNodeList.length - 1)) {
							//结束
							uni.showModal({
								title: '提示',
								content: "设置已经完成",
								showCancel: false
							})
							that.apply_run = 0
						} else {
							//下一个
							that.apply_idx++
							that.apply_retry = 0
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeDay()
								}, 200)
							}


						}
					} else {
						//遇到错误，重试
						if (that.apply_retry < retry_max) {
							that.nodeList[real_idx].run_status = 1
							that.apply_retry++
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeDay()
								}, 200)
							}
						} else {
							//超过重试次数，失败
							that.nodeList[real_idx].run_status = -1
							//判断是否结束
							if (that.apply_idx == (that.selectNodeList.length - 1)) {
								//结束
								uni.showModal({
									title: '提示',
									content: "设置已经完成",
									showCancel: false
								})
								that.apply_run = 0
							} else {
								//下一个
								that.apply_idx++
								that.apply_retry = 0
								if (that.apply_run) {
									setTimeout(function() {
										that.loopSetNodeDay()
									}, 200)
								}
							}
						}
					}
				})

			},
			setNodeDay(addr, tn, day) {
				var promise = new Promise(function(resolve, reject) {
					var token = getApp().getToken()
					api.myRequest({
						url: '/Api/Device/Gw/SetNodeDay',
						method: 'PUT',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authorization': 'Bearer ' + token + ''
						},
						data: {
							addr: addr,
							tn: tn,
							day: day
						},
					}, false).then(res => {
						resolve(res);
					}).catch(err => {
						console.log(err)
						reject(err);
					})
				});
				return promise;
			},

			confirmSetCalc() {
				var that = this
				this.selectNodeList = []
				for(var i=0;i<this.nodeList.length;i++){
					if(this.nodeList[i].select>0){
						this.selectNodeList.push(this.nodeList[i])
					}
				}
				console.info("已选择:"+this.selectNodeList.length)
				
				that.hideModalCalc()
				uni.showModal({
					title: '提示',
					content: '请注意,您即将对' + that.selectNum + '个栏位设置10圈出料(g):' + that.set_calc + ' ,您的操作将会被系统记录',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							for (var i = 0; i < that.nodeList.length; i++) {
								that.nodeList[i].run_status = 0
							}

							that.apply_idx = 0
							that.apply_run = 1
							that.apply_retry = 0
							that.loopSetNodeCalcFeed()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			loopSetNodeCalcFeed() {
				var that = this
				if (!that.apply_run) {
					return;
				}
				var node = that.selectNodeList[that.apply_idx]
				var real_idx = that.getIdxBySn(node.sn)
				that.nodeList[real_idx].run_status = 1
				that.setNodeCalcFeed(node.addr, node.tn, that.set_calc).then(function(res) {
					if (res.code >= 0) {
						that.nodeList[real_idx].run_status = 2
						//判断是否结束
						if (that.apply_idx == (that.selectNodeList.length - 1)) {
							//结束
							uni.showModal({
								title: '提示',
								content: "设置已经完成",
								showCancel: false
							})
							that.apply_run = 0
						} else {
							//下一个
							that.apply_idx++
							that.apply_retry = 0
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeCalcFeed()
								}, 200)
							}


						}
					} else {
						//遇到错误，重试
						if (that.apply_retry < retry_max) {
							that.nodeList[real_idx].run_status = 1
							that.apply_retry++
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeCalcFeed()
								}, 200)
							}
						} else {
							//超过重试次数，失败
							that.nodeList[real_idx].run_status = -1
							//判断是否结束
							if (that.apply_idx == (that.selectNodeList.length - 1)) {
								//结束
								uni.showModal({
									title: '提示',
									content: "设置已经完成",
									showCancel: false
								})
								that.apply_run = 0
							} else {
								//下一个
								that.apply_idx++
								that.apply_retry = 0
								if (that.apply_run) {
									setTimeout(function() {
										that.loopSetNodeCalcFeed()
									}, 200)
								}
							}
						}
					}
				})
			},
			setNodeCalcFeed(addr, tn, calFeed) {
				var promise = new Promise(function(resolve, reject) {
					var token = getApp().getToken()
					api.myRequest({
						url: '/Api/Device/Gw/SetNodeCalcFeed',
						method: 'PUT',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authorization': 'Bearer ' + token + ''
						},
						data: {
							addr: addr,
							tn: tn,
							calFeed: calFeed
						},
					}, false).then(res => {
						resolve(res);
					}).catch(err => {
						console.log(err)
						reject(err);
					})
				});
				return promise;
			},
			
			confirmSetStop(){
				var that = this
				this.selectNodeList = []
				for(var i=0;i<this.nodeList.length;i++){
					if(this.nodeList[i].select>0){
						this.selectNodeList.push(this.nodeList[i])
					}
				}
				console.info("已选择:"+this.selectNodeList.length)
				
				uni.showModal({
					title: '提示',
					content: '请注意,您即将对' + that.selectNum + '个栏位停止自动饲喂,您的操作将会被系统记录',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							for (var i = 0; i < that.nodeList.length; i++) {
								that.nodeList[i].run_status = 0
							}
				
							that.apply_idx = 0
							that.apply_run = 1
							that.apply_retry = 0
							that.loopSetNodeStop()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			loopSetNodeStop(){
				var that = this
				if (!that.apply_run) {
					return;
				}
				var node = that.selectNodeList[that.apply_idx]
				var real_idx = that.getIdxBySn(node.sn)
				that.nodeList[real_idx].run_status = 1
				that.setNodeStop(node.addr, node.tn,node.sn).then(function(res) {
					if (res.code >= 0) {
						that.nodeList[real_idx].run_status = 2
						//判断是否结束
						if (that.apply_idx == (that.selectNodeList.length - 1)) {
							//结束
							uni.showModal({
								title: '提示',
								content: "设置已经完成",
								showCancel: false
							})
							that.apply_run = 0
						} else {
							//下一个
							that.apply_idx++
							that.apply_retry = 0
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeStop()
								}, 200)
							}
				
				
						}
					} else {
						//遇到错误，重试
						if (that.apply_retry < retry_max) {
							that.nodeList[real_idx].run_status = 1
							that.apply_retry++
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeStop()
								}, 200)
							}
						} else {
							//超过重试次数，失败
							that.nodeList[real_idx].run_status = -1
							//判断是否结束
							if (that.apply_idx == (that.selectNodeList.length - 1)) {
								//结束
								uni.showModal({
									title: '提示',
									content: "设置已经完成",
									showCancel: false
								})
								that.apply_run = 0
							} else {
								//下一个
								that.apply_idx++
								that.apply_retry = 0
								if (that.apply_run) {
									setTimeout(function() {
										that.loopSetNodeStop()
									}, 200)
								}
							}
						}
					}
				})
			},
			setNodeStop(addr, tn,sn){
				var model = ''
				if(sn[0]=='3'){
					model = 'fg'
				}else{
					model = 'feed'
				}
				var promise = new Promise(function(resolve, reject) {
					var token = getApp().getToken()
					api.myRequest({
						url: '/Api/Device/Gw/SetNodeMode',
						method: 'PUT',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authorization': 'Bearer ' + token + ''
						},
						data: {
							addr: addr,
							tn: tn,
							mode: 0,
							model:model,
						},
					}, false).then(res => {
						resolve(res);
					}).catch(err => {
						console.log(err)
						reject(err);
					})
				});
				return promise;
			},

			onSetHnum(){
				var that = this
				var hnum = that.set_hnum_prefix + that.set_hnum
				that.nodeList[that.cur_edit_hnum_idx].hnum = hnum
				that.hideModalHnum()
			},
			confirmSetHnum(){
				var that = this
				this.selectNodeList = []
				for(var i=0;i<this.nodeList.length;i++){
					if(this.nodeList[i].select>0){
						this.selectNodeList.push(this.nodeList[i])
					}
				}
				console.info("已选择:"+this.selectNodeList.length)
				
				uni.showModal({
					title: '提示',
					content: '请注意,您即将对' + that.selectNum + '个栏位设置栏位号,您的操作将会被系统记录',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							for (var i = 0; i < that.nodeList.length; i++) {
								that.nodeList[i].run_status = 0
							}
				
							that.apply_idx = 0
							that.apply_run = 1
							that.apply_retry = 0
							that.loopSetNodeHnum()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			loopSetNodeHnum(){
				var that = this
				if (!that.apply_run) {
					return;
				}
				var node = that.selectNodeList[that.apply_idx]
				var real_idx = that.getIdxBySn(node.sn)
				that.nodeList[real_idx].run_status = 1
				that.setNodeHnum(node.addr, node.tn,node.hnum).then(function(res) {
					if (res.code >= 0) {
						that.nodeList[real_idx].run_status = 2
						//判断是否结束
						if (that.apply_idx == (that.selectNodeList.length - 1)) {
							//结束
							uni.showModal({
								title: '提示',
								content: "设置已经完成",
								showCancel: false
							})
							that.apply_run = 0
						} else {
							//下一个
							that.apply_idx++
							that.apply_retry = 0
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeHnum()
								}, 200)
							}
				
				
						}
					} else {
						//遇到错误，重试
						if (that.apply_retry < retry_max) {
							that.nodeList[real_idx].run_status = 1
							that.apply_retry++
							if (that.apply_run) {
								setTimeout(function() {
									that.loopSetNodeHnum()
								}, 200)
							}
						} else {
							//超过重试次数，失败
							that.nodeList[real_idx].run_status = -1
							//判断是否结束
							if (that.apply_idx == (that.selectNodeList.length - 1)) {
								//结束
								uni.showModal({
									title: '提示',
									content: "设置已经完成",
									showCancel: false
								})
								that.apply_run = 0
							} else {
								//下一个
								that.apply_idx++
								that.apply_retry = 0
								if (that.apply_run) {
									setTimeout(function() {
										that.loopSetNodeHnum()
									}, 200)
								}
							}
						}
					}
				})
			},
			setNodeHnum(addr, tn,hnum){
				var promise = new Promise(function(resolve, reject) {
					var token = getApp().getToken()
					api.myRequest({
						url: '/Api/Device/Gw/SetNodeHnum',
						method: 'PUT',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authorization': 'Bearer ' + token + ''
						},
						data: {
							addr: addr,
							tn: tn,
							hnum: hnum
						},
					}, false).then(res => {
						resolve(res);
					}).catch(err => {
						console.log(err)
						reject(err);
					})
				});
				return promise;
			},
			
			getIdxBySn(sn){
				var idx = -1
				for(var i=0;i<this.nodeList.length;i++){
					if(sn==this.nodeList[i].sn){
						idx = i
						break
					}
				}
				return idx
			}
		}
	}
</script>

<style>
	.node-pannel {
		/* min-height: 180rpx; */
		border-radius: 5rpx;
		/* opacity: 0.9; */
		/* background: url("https://www.hozenn.com/iot/img/house.png") 80% 50% / 40% no-repeat linear-gradient(to top, rgba(255, 255, 255, 0.95)); */
		/* background-image:linear-gradient(to top, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)),url('https://www.hozenn.com/iot/img/house.png'); */
		background-repeat: no-repeat;
		background-size: 20%;
		background-position: 55% 50%;
		/* background-color: rgba(100, 100, 100, 0.3); */
		border: 1px solid rgba(200, 200, 200, 0.9);
		box-shadow: 0 2px 4px rgba(100, 100, 100, 0.3);
	}

	.bg-alarm {
		background-color: rgba(255, 96, 48, 0.3);
		/* border: 1px solid #e54d42; */
	}

	.bg-online {
		background-color: rgba(0, 134, 0, 0.3);
		border: 1px solid #0d8400;
	}

	.bg-offline {
		background-color: rgba(135, 135, 135, 0.3);
		border: 1px solid #878787;
	}

	.split {
		border-right: 1px solid #5e5e5e;
	}

	.opcity {
		opacity: 0.8;
	}

	.cu-bar .search-form {
		background-color: rgba(100, 100, 100, 0.1);
	}

	.bottom-bar {
		height: 50px;
		border-top: 1px solid #aaa;
		/* background-color: aliceblue; */
		/* border-top:1px solid #878787; */
	}

	.tab-alarm {
		/* min-height: 180rpx; */
		background-color: rgba(100, 100, 100, 0.5);
		height: 40px;
		border-radius: 20px 00% 0% 20px;
		/* border: 1px solid #e54d42; */
	}

	.tab-notice {
		/* min-height: 180rpx; */
		background-color: rgba(100, 100, 100, 0.5);
		height: 40px;
		border-radius: 0px 20px 20px 0px;
		/* border: 1px solid #e54d42; */
	}

	.border-select {
		border: 2px solid rgb(60, 124, 255);
		border-radius: 5px;
	}

	.bg-select {
		background-color: rgba(200, 200, 200, 0.3);
		border: 2px solid #0d8400;
		border-radius: 5px;
	}

	.bg-unselect {
		background-color: rgba(200, 200, 200, 0.3);
		border: 1px solid #dadada;
		border-radius: 5px;
	}

	.cu-modal {
		z-index: 2;
	}
</style>